<html>
<head><meta charset="utf-8"><title>rustc_target Target from string · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html">rustc_target Target from string</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244102955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244102955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244102955">(Jun 28 2021 at 05:15)</a>:</h4>
<p>Kind of a stupid question but how do i get a <code>rustc_target::Target</code> from its target triple? i cant find anything to do that lol</p>



<a name="244103328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244103328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244103328">(Jun 28 2021 at 05:24)</a>:</h4>
<p>alternatively, a <code>DataLayout</code> from its layout string, theres only an option to get it from a Target :(</p>



<a name="244115206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244115206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244115206">(Jun 28 2021 at 08:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="276242">Riccardo D'Ambrosio</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/rustc_target.20Target.20from.20string/near/244102955">said</a>:</p>
<blockquote>
<p>Kind of a stupid question but how do i get a <code>rustc_target::Target</code> from its target triple? i cant find anything to do that lol</p>
</blockquote>
<p>If you only care about built-in targets <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/fn.load_builtin.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/fn.load_builtin.html</a>. Can also check the callers of <code>load_builtin</code> too.</p>



<a name="244115384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244115384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244115384">(Jun 28 2021 at 08:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="276242">Riccardo D'Ambrosio</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/rustc_target.20Target.20from.20string/near/244103328">said</a>:</p>
<blockquote>
<p>alternatively, a <code>DataLayout</code> from its layout string, theres only an option to get it from a Target <span aria-label="frown" class="emoji emoji-1f641" role="img" title="frown">:frown:</span></p>
</blockquote>
<p>Doesn't look like you can do that, beyond just refactoring <code>TargetDataLayout::parse</code>. into a couple methods.</p>



<a name="244115507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244115507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244115507">(Jun 28 2021 at 08:32)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> should have mentioned from the public api lol, im working with a codegen</p>



<a name="244115536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244115536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244115536">(Jun 28 2021 at 08:33)</a>:</h4>
<p>yeah i ripped out the parsing logic and im just using that for now</p>



<a name="244115576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244115576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244115576">(Jun 28 2021 at 08:33)</a>:</h4>
<p>how come you cant access all parts of rustc crates from rustc_private anyways <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="244115868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244115868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244115868">(Jun 28 2021 at 08:37)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.Target.html#method.search">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.Target.html#method.search</a> is public.</p>



<a name="244115899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244115899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244115899">(Jun 28 2021 at 08:37)</a>:</h4>
<p>rustc_private feature only governs access to the crates, not to the API within; and <code>load_builtin</code> is not made public.</p>



<a name="244116060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244116060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244116060">(Jun 28 2021 at 08:39)</a>:</h4>
<p>yeah, although it makes reusing parts of rustc a bit harder, especially things like the codegen that has very few public APIs</p>



<a name="244133566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustc_target%20Target%20from%20string/near/244133566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustc_target.20Target.20from.20string.html#244133566">(Jun 28 2021 at 11:58)</a>:</h4>
<p><span class="user-mention" data-user-id="276242">@Riccardo D'Ambrosio</span> you can always open a PR making things public, as long as you say why they're useful it will probably be accepted</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>